package com.ncloud.resman.mapper;

import com.alibaba.fastjson.JSONObject;
import com.ncloud.resman.entity.DeviceSub;

import java.util.List;

import org.apache.ibatis.annotations.*;

/**
 * Created by shiqiang on 2017/8/14.
 */
@Mapper
public interface SwitchSubMapper {
    @Insert("insert into res_device_switch_sub(sub_id,device_id, sub_type, state,sub_no, purpose,create_user, create_date, update_user, update_date)"
            + " values(#{subId},#{deviceId},#{subType},#{state},#{subNo},#{purpose},#{createUser},#{createDate},#{updateUser},#{updateDate})")
    int insertSwitchSub(DeviceSub deviceSub);
    @Update("update res_device_switch_sub set state =#{state},purpose =#{purpose},update_user =#{updateUser},update_date =#{updateDate} " +
            " where device_id =#{deviceId} and sub_id =#{subId}")
    int updateSwitchSub(DeviceSub deviceSub);

    @Update("update res_device_switch_sub set purpose =#{purpose},update_user =#{updateUser},update_date =#{updateDate} " +
            " where device_id =#{deviceId} and sub_id =#{subId}")
    int updateSwitchSubPurpose(DeviceSub deviceSub);
    
    @Update("update res_device_switch_sub set purpose =#{purpose},sub_type=#{subType},state=#{state},update_user =#{updateUser},update_date =now() " +
            " where device_id =#{deviceId} and sub_no =#{subNo}")
    int updateSwitchSubSubNoInfo(DeviceSub deviceSub);
    
    @Select("SELECT CONCAT(sub_id,'') as sub_id, CONCAT(device_id,'') as device_id, sub_type, state, purpose "
			+ "FROM res_device_switch_sub where device_id = #{deviceId}")
	@Results({
		@Result(column="sub_id",property="subId"),@Result(column="device_id",property="deviceId"),
		@Result(column="sub_type",property="subType"),@Result(column="state",property="state"),
		@Result(column="purpose",property="purpose")})
	List<JSONObject> getDeviceSwitchSubById(Long deviceId);//根据设备id查询设备交换机接口信息

    /*删除*/
    @Delete(value = "delete from res_device_switch_sub WHERE device_id = #{0}")
    public int deleteSwitchSub(Long deviceId);
    
    @Select("SELECT CONCAT(sub_no,'') as sub_no, CONCAT(device_id,'') as device_id, f_get_dict('sub_type',sub_type) "
    		+ "as sub_type,f_get_dict('sub_state',state) as state, purpose FROM res_device_switch_sub where "
    		+ "device_id = #{deviceId}")
	@Results({
		@Result(column="sub_no",property="subNo"),@Result(column="device_id",property="deviceId"),
		@Result(column="sub_type",property="subType"),@Result(column="state",property="state"),
		@Result(column="sn_num",property="snNum"),@Result(column="purpose",property="purpose"),
		@Result(column="sub_no",property="subNo")
	})
	List<DeviceSub> exportDeviceSwitchSub(Long deviceId);//根据设备snNum查询设备交换机接口信息
}
